package com.njd.test.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.njd.test.controller.IndexController; 
import com.njd.test.controller.PressureController; 
import com.njd.test.entity.Data;
import com.njd.test.entity.Module;
import com.njd.test.entity.Project;
import com.njd.test.entity.R;

public class JfinalConfig extends JFinalConfig {
	public static String BASE_PATH = "/";
	
	@Override
	public void configConstant(Constants me) {
		PropKit.use("a_little_config.txt");
		me.setDevMode(PropKit.getBoolean("devMode", false));
		me.setViewType(ViewType.JSP); 	
		BASE_PATH = PropKit.get("basePath", "/");
		
		me.setBaseViewPath("/WEB-INF/page");
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/chart", PressureController.class, "Pressure");
	}

	@Override
	public void configPlugin(Plugins me) { 
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
		me.add(c3p0Plugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		arp.addMapping("data", R.data.id, Data.class);
		arp.addMapping("project", R.project.id, Project.class);
		arp.addMapping("module", R.module.id, Module.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}

}
